<?php
namespace App\Adshopuser\Models;
use Common\BaseModel;
class BShopGoodsCategory extends BaseModel
{
    public $res;
    public $expire;

    public function initialize()
    {
        parent::initialize();
        $this->setSource('b_shop_goods_category');
    }

    public function get_list($pid = 0){
        if($pid > 0){
            $where['conditions'] = 'p_id = '.$pid;
        } else {
            $where['conditions'] = 'level_id = 1';
        }
        $where['order'] = 'sort asc,id desc';
        $list = $this->find($where)->toarray();
        foreach($list as $key=>$value){
            $list[$key]['id'] = (int)$value['id'];
        }
        return $list;
    }

    /**
     * 根据店铺所选的分类
     */
    public function findShopPath($shop_id,$path){
        $conditions="shop_id in(0,$shop_id) AND path like '{$path}%' AND deleted=0";
        $getList = $this->find(array(
            $conditions,
            'columns'=>"id as value,category_name as label,p_id as pid"
        ))->toarray();
        return $getList;
    }

}
